﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
using System.Collections;
using Word;
using System.IO;
using LHS.Core.TableInfo;
using MS.Core.Constants.Objects;
using MS.Core.Base.Transaction;
using System.Collections.Specialized;


namespace LHS.Win
{
    public partial class frmNoiSoi : Form
    {
        LHS.Core.Clinical.ClinicalController objController = new LHS.Core.Clinical.ClinicalController();
        // Methods
        public frmNoiSoi(string ID, string HoTen, string clrISN, bool Insert, string NgayKham)
        {
            this.InitializeComponent();
            this.ImagePath = ConfigurationManager.AppSettings["ImagePath"];
            this.tbID.Text = ID;
            this.tbHoTen.Text = HoTen;
            this._clrISN = clrISN;
            this._Insert = Insert;
            this._NgayKham = NgayKham;
        }

        private void btAdd_Click(object sender, EventArgs e)
        {
            this.tvNoiSoi_DoubleClick(sender, e);
            this.NoiSoiCheck();
        }

        private void btCapNhat_Click(object sender, EventArgs e)
        {
            int num = 0;
            if (this.CheckInputData())
            {
                TransactionManager trans = TransactionManager.ThreadTransactionMgr();
                try
                {
                    trans.BeginTransaction();
                    List<ExpressionObject> param = new List<ExpressionObject>();
                    param.Add(new ExpressionObject(InfoScanResult.CLRISN, this._clrISN));
                    objController.DeleteRow(InfoScanResult.TABLENAME, param);

                    ArrayList list = new ArrayList();
                    ArrayList list2 = new ArrayList();
                    string text = "";
                    string str2 = "";
                    int count = this.lbNoiSoi.Items.Count;
                    for (int i = 0; i < count; i++)
                    {
                        list.Add(this.lbNoiSoi.Items[i].ToString());
                    }
                    DataTable dtInnerScan;
                    for (int j = 0; j < list.Count; j++)
                    {
                        List<ExpressionObject> paramInnerScan = new List<ExpressionObject>();
                        paramInnerScan.Add(new ExpressionObject("nscNameChild", list[j].ToString()));
                        dtInnerScan = objController.GetData("vw_InnerScan", paramInnerScan);
                        if (dtInnerScan.Rows.Count == 0)
                            continue;

                        str2 = list[j].ToString();
                        str2 = str2.Substring(str2.IndexOf('(') + 1, 1);
                        if (str2.ToUpper() == "T")
                        {
                            num = 1;
                        }
                        else if (str2.ToUpper() == "P")
                        {
                            num = 2;
                        }
                        if (!(dtInnerScan.Rows[0]["Root3"].ToString() != ""))
                        {
                            goto Label_0571;
                        }
                        list2.Add(dtInnerScan.Rows[0]["nscISNLevelThree"].ToString());
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "167")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtOngTaiNgoaiP.Text;
                                    break;

                                case 1:
                                    text = this.txtOngTaiNgoaiT.Text;
                                    goto Label_020A;
                            }
                        }
                    Label_020A:
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "168")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtMangNhiP.Text;
                                    break;

                                case 1:
                                    text = this.txtMangNhiT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "170")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtCuonDuoiP.Text;
                                    break;

                                case 1:
                                    text = this.txtCuonDuoiT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "169")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtVachNganP.Text;
                                    break;

                                case 1:
                                    text = this.txtVachNganT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "171")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtCuonGiuaP.Text;
                                    break;

                                case 1:
                                    text = this.txtCuonGiuaT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "172")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtKheGiuaP.Text;
                                    break;

                                case 1:
                                    text = this.txtKheGiuaT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "173")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtKheTrenP.Text;
                                    break;

                                case 1:
                                    text = this.txtKheTrenT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "174")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtMomMocP.Text;
                                    break;

                                case 1:
                                    text = this.txtMomMocT.Text;
                                    break;
                            }
                        }

                        if (text != "")
                        {
                            ListDictionary paramSR = new ListDictionary();
                            paramSR.Add(InfoScanResult.CLRISN, this._clrISN);
                            paramSR.Add(InfoScanResult.NSCISN, dtInnerScan.Rows[0]["nscISNLevelThree"].ToString());
                            paramSR.Add(InfoScanResult.SRTSCANOUTLIST, this.tbNoiSoiNgoaiDanhSach.Text.ToString());
                            paramSR.Add(InfoScanResult.SRTOPINION, this.txtCamNghi.Text.ToString());
                            paramSR.Add(InfoScanResult.SRTSUGGESTION, this.txtDeNghi.Text.ToString());

                            paramSR.Add(InfoScanResult.NSCISNROOT, dtInnerScan.Rows[0]["Root3"].ToString());
                            paramSR.Add(InfoScanResult.SRTPOSITIONSTATUS, num); //2: phải l; 1 : trái
                            paramSR.Add(InfoScanResult.SRTSCANLISTSTRING, text);
                            objController.Exec_StoreProc("sp_ScanResult", paramSR);
                        }
                        continue;
                    Label_0571:
                        list2.Add(dtInnerScan.Rows[0]["nscISNChild"].ToString());
                        if (dtInnerScan.Rows[0][InfoInnerScan.NSCISN].ToString() == "85")
                        {
                            text = this.txtHaHong.Text;
                        }
                        if (dtInnerScan.Rows[0][InfoInnerScan.NSCISN].ToString() == "3")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtVomHongP.Text;
                                    break;

                                case 1:
                                    text = this.txtVomHongT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0][InfoInnerScan.NSCISN].ToString() == "4")
                        {
                            text = this.txtThanhQuan.Text;
                        }

                        if (text != "")
                        {
                            ListDictionary paramSR = new ListDictionary();
                            paramSR.Add(InfoScanResult.CLRISN, this._clrISN);
                            paramSR.Add(InfoScanResult.NSCISN, dtInnerScan.Rows[0]["nscISNChild"].ToString());
                            paramSR.Add(InfoScanResult.SRTSCANOUTLIST, this.tbNoiSoiNgoaiDanhSach.Text.ToString());
                            paramSR.Add(InfoScanResult.SRTOPINION, this.txtCamNghi.Text.ToString());
                            paramSR.Add(InfoScanResult.SRTSUGGESTION, this.txtDeNghi.Text.ToString());

                            paramSR.Add(InfoScanResult.NSCISNROOT, dtInnerScan.Rows[0][InfoInnerScan.NSCISN].ToString());
                            paramSR.Add(InfoScanResult.SRTPOSITIONSTATUS, num); //2: phải l; 1 : trái
                            paramSR.Add(InfoScanResult.SRTSCANLISTSTRING, text);
                            objController.Exec_StoreProc("sp_ScanResult", paramSR);
                        }
                    }
                   
                    this.NoiSoiNgoaiDS();
                    MessageBox.Show("Nội soi đã được lưu", "Cập Nhật Nội Soi", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    list.Clear();
                    list2.Clear();
                    count = 0;
                    trans.CommitTransaction();
                }
                catch (Exception ex)
                {
                    trans.RollbackTransaction();
                    Class.ShowException(ex);
                }

            }
        }

        private void btHinhAnh_Click(object sender, EventArgs e)
        {
            frmCapNhatAnh anh = new frmCapNhatAnh(this._clrISN, this._NgayKham);
            anh.ShowInTaskbar = false;
            anh.ShowDialog();
        }

        private void btIn_Click(object sender, EventArgs e)
        {
            object obj8;
            Range range;
            ApplicationClass class2 = new ApplicationClass();
            object missing = Type.Missing;
            object link = false;
            object dataType = 1;
            try
            {
                obj8 = System.Windows.Forms.Application.StartupPath + "/PhieuketquaNoisoi02.doc";
            }
            catch (Exception exception)
            {
                Class.ShowException(exception);
                return;
            }
            Document document = class2.Documents.Open(ref obj8, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
            Document document2 = class2.Documents.Add(ref missing, ref missing, ref missing, ref missing);
            document.Select();
            class2.Selection.Copy();
            document2.Select();
            class2.Selection.PasteSpecial(ref missing, ref link, ref missing, ref link, ref dataType, ref missing, ref missing);
            document.Close(ref link, ref missing, ref missing);

            class2.Visible = true;
            class2.Activate();

            ArrayList arrColumnSick = new ArrayList();
            arrColumnSick.Add(InfoSicks.SCKNAME);
            List<ExpressionObject> param = new List<ExpressionObject>();
            param.Add(new ExpressionObject(InfoClinicalSick.CLRISN, this._clrISN));
            DataTable dtSckName = objController.GetData("vw_ClinicalSicks", arrColumnSick, param);
            string str = "";
            for (int i = 0; i < dtSckName.Rows.Count; i++)
            {
                if (str == "")
                {
                    str = dtSckName.Rows[i][InfoSicks.SCKNAME].ToString();
                }
                else
                {
                    str = str + "," + dtSckName.Rows[i][InfoSicks.SCKNAME].ToString();
                }
            }

            ArrayList arrCoClinicalRecord = new ArrayList();
            arrCoClinicalRecord.Add(InfoPatients.PATID);
            arrCoClinicalRecord.Add(InfoPatients.PATNAME);
            arrCoClinicalRecord.Add(InfoPatients.PATAGE);
            arrCoClinicalRecord.Add(InfoPatients.PATSEX);
            arrCoClinicalRecord.Add(InfoPatients.PATADDRESS);
            arrCoClinicalRecord.Add(InfoEmployees.EMPNAME);
            arrCoClinicalRecord.Add("Day(" + InfoClinicalRecord.CLREXAMINATIONDATE + ") as Ngay");
            arrCoClinicalRecord.Add("Month(" + InfoClinicalRecord.CLREXAMINATIONDATE + ") as Thang");
            arrCoClinicalRecord.Add("Year(" + InfoClinicalRecord.CLREXAMINATIONDATE + ") as Nam");
            arrCoClinicalRecord.Add(InfoClinicalRecord.CLRPATHOLOGICALSIGNS);
            DataTable dtClinicalRecord = objController.GetData("dbo.vw_ClinicalRecord", arrCoClinicalRecord, param);

            int num2 = 0;
            document2.Sentences.Item(11).Characters.Item(1).Text = this.tbHoTen.Text.Replace(".", "");
            document2.Sentences.Item(13).Characters.Item(1).Text = dtClinicalRecord.Rows[0][InfoPatients.PATAGE].ToString().Replace(".", "");
            document2.Sentences.Item(15).Characters.Item(1).Text = dtClinicalRecord.Rows[0][InfoPatients.PATSEX].ToString().Replace(".", "");
            document2.Sentences.Item(0x12).Characters.Item(1).Text = dtClinicalRecord.Rows[0][InfoPatients.PATADDRESS].ToString().Replace(".", "");
            document2.Sentences.Item(20).Characters.Item(1).Text = dtClinicalRecord.Rows[0][InfoPatients.PATID].ToString().Replace(".", "");
            document2.Sentences.Item(0x17).Characters.Item(1).Text = str.Replace(".", "");
            document2.Sentences.Item(0x1a).Characters.Item(1).Text = dtClinicalRecord.Rows[0][InfoClinicalRecord.CLRPATHOLOGICALSIGNS].ToString().Replace(".", "");
            document2.Sentences.Item(0x1c).Characters.Item(1).Text = dtClinicalRecord.Rows[0][InfoEmployees.EMPNAME].ToString().ToUpper().Replace(".", "");
            string str2 = "";
            if (dtClinicalRecord.Rows[0]["Ngay"].ToString().Length < 2)
            {
                str2 = "0" + dtClinicalRecord.Rows[0]["Ngay"].ToString();
            }
            else
            {
                str2 = dtClinicalRecord.Rows[0]["Ngay"].ToString();
            }
            string str3 = "";
            if (dtClinicalRecord.Rows[0]["Thang"].ToString().Length < 2)
            {
                str3 = "0" + dtClinicalRecord.Rows[0]["Thang"].ToString();
            }
            else
            {
                str3 = dtClinicalRecord.Rows[0]["Thang"].ToString();
            }
            document2.Sentences.Item(0x65).Characters.Item(1).Text = str2 + "/" + str3 + "/" + dtClinicalRecord.Rows[0]["Nam"].ToString();
            document2.Sentences.Item(0x67).Characters.Item(1).Text = dtClinicalRecord.Rows[0][InfoEmployees.EMPNAME].ToString().ToUpper().Replace(".", "");

            #region Fill Clinical
            
            ListDictionary orderbySR = new ListDictionary();
            orderbySR.Add(InfoScanResult.NSCISNROOT, "asc");
            orderbySR.Add(InfoScanResult.SRTPOSITIONSTATUS, "asc");
            DataTable dtSR = objController.GetData("vw_ScanResult_InnerScan", param, orderbySR);

            string str4 = "";
            string str5 = "";
            string str6 = "";
            string str7 = "";
            string str8 = "";
            string str9 = "";
            string str10 = "";
            string str11 = "";
            string str12 = "";
            string str13 = "";
            string str14 = "";
            string str15 = "";
            string str16 = "";
            string str17 = "";
            string str18 = "";
            string str19 = "";
            string str20 = "";
            string str21 = "";
            string str22 = "";
            string str23 = "";
            string str25 = "";
            string str33 = "";
            for (int j = 0; j < dtSR.Rows.Count; j++)
            {
                if (dtSR.Rows[j][InfoInnerScan.NSCISNROOT].ToString() == "167")
                {
                    switch (dtSR.Rows[j][InfoScanResult.SRTPOSITIONSTATUS].ToString())
                    {
                        case "1":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str12 == "")
                                {
                                    str12 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str12 = str12 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str12 == "")
                            {
                                str12 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;

                        case "2":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str20 == "")
                                {
                                    str20 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str20 = str20 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str20 == "")
                            {
                                str20 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            goto Label_0A34;
                    }
                }
            Label_0A34:
                if (dtSR.Rows[j][InfoInnerScan.NSCISNROOT].ToString() == "168")
                {
                    switch (dtSR.Rows[j][InfoScanResult.SRTPOSITIONSTATUS].ToString())
                    {
                        case "1":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str13 == "")
                                {
                                    str13 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str13 = str13 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str13 == "")
                            {
                                str13 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;

                        case "2":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str21 == "")
                                {
                                    str21 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str21 = str21 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str21 == "")
                            {
                                str21 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;
                    }
                }
                if (dtSR.Rows[j][InfoInnerScan.NSCISNROOT].ToString() == "169")
                {
                    switch (dtSR.Rows[j][InfoScanResult.SRTPOSITIONSTATUS].ToString())
                    {
                        case "1":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str4 == "")
                                {
                                    str4 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str4 = str4 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str4 == "")
                            {
                                str4 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;

                        case "2":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str14 == "")
                                {
                                    str14 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str14 = str14 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str14 == "")
                            {
                                str14 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;
                    }
                }
                if (dtSR.Rows[j][InfoInnerScan.NSCISNROOT].ToString() == "170")
                {
                    str25 = dtSR.Rows[j][InfoScanResult.SRTPOSITIONSTATUS].ToString();
                    if (str25.ToUpper() == "1")
                    {
                        if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                        {
                            if (str5 == "")
                            {
                                str5 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                            }
                            else
                            {
                                str5 = str5 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                            }
                        }
                        else if (str5 == "")
                        {
                            str5 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                        }
                    }
                    if (str25.ToUpper() == "2")
                    {
                        if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                        {
                            if (str15 == "")
                            {
                                str15 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                            }
                            else
                            {
                                str15 = str15 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                            }
                        }
                        else if (str15 == "")
                        {
                            str15 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                        }
                    }
                }
                if (dtSR.Rows[j][InfoInnerScan.NSCISNROOT].ToString() == "171")
                {
                    switch (dtSR.Rows[j][InfoScanResult.SRTPOSITIONSTATUS].ToString())
                    {
                        case "1":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str6 == "")
                                {
                                    str6 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str6 = str6 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str6 == "")
                            {
                                str6 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;

                        case "2":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str16 == "")
                                {
                                    str16 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str16 = str16 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str16 == "")
                            {
                                str16 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;
                    }
                }
                if (dtSR.Rows[j][InfoInnerScan.NSCISNROOT].ToString() == "172")
                {
                    switch (dtSR.Rows[j][InfoScanResult.SRTPOSITIONSTATUS].ToString())
                    {
                        case "1":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str8 == "")
                                {
                                    str8 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str8 = str8 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str8 == "")
                            {
                                str8 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;

                        case "2":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str18 == "")
                                {
                                    str18 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str18 = str18 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str18 == "")
                            {
                                str18 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;
                    }
                }
                if (dtSR.Rows[j][InfoInnerScan.NSCISNROOT].ToString() == "173")
                {
                    switch (dtSR.Rows[j][InfoScanResult.SRTPOSITIONSTATUS].ToString())
                    {
                        case "1":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str7 == "")
                                {
                                    str7 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str7 = str7 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str7 == "")
                            {
                                str7 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;

                        case "2":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str17 == "")
                                {
                                    str17 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str17 = str17 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str17 == "")
                            {
                                str17 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;
                    }
                }
                if (dtSR.Rows[j][InfoInnerScan.NSCISNROOT].ToString() == "174")
                {
                    switch (dtSR.Rows[j][InfoScanResult.SRTPOSITIONSTATUS].ToString())
                    {
                        case "1":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str9 == "")
                                {
                                    str9 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str9 = str9 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str9 == "")
                            {
                                str9 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;

                        case "2":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str19 == "")
                                {
                                    str19 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str19 = str19 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str19 == "")
                            {
                                str19 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;
                    }
                }
                if (dtSR.Rows[j][InfoInnerScan.NSCISNROOT].ToString() == "3")
                {
                    switch (dtSR.Rows[j][InfoScanResult.SRTPOSITIONSTATUS].ToString())
                    {
                        case "1":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str23 == "")
                                {
                                    str23 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str23 = str23 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str23 == "")
                            {
                                str23 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;

                        case "2":
                            if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                            {
                                if (str22 == "")
                                {
                                    str22 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                                else
                                {
                                    str22 = str22 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                                }
                            }
                            else if (str22 == "")
                            {
                                str22 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            break;
                    }
                }
                if (dtSR.Rows[j][InfoInnerScan.NSCISNROOT].ToString() == "85")
                {
                    if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                    {
                        if (str10 == "")
                        {
                            str10 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                        }
                        else
                        {
                            str10 = str10 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                    else if (str10 == "")
                    {
                        str10 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                    }
                }
                if (dtSR.Rows[j][InfoInnerScan.NSCISNROOT].ToString() == "4")
                {
                    if (dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                    {
                        if (str11 == "")
                        {
                            str11 = dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                        }
                        else
                        {
                            str11 = str11 + "," + dtSR.Rows[j][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                    else if (str11 == "")
                    {
                        str11 = dtSR.Rows[j][InfoScanResult.SRTSCANLISTSTRING].ToString();
                    }
                }
            }
            if (str20 == "")
            {
                str20 = "sạch khỏe";
                document2.Sentences.Item(num2 + 0x22).Characters.Item(1).Text = str20;
            }
            else
            {
                document2.Sentences.Item(num2 + 0x22).Characters.Item(1).Text = str20.ToUpper().Replace(".", "");
            }
            if (str12 == "")
            {
                str12 = "sạch khỏe";
                document2.Sentences.Item(num2 + 0x25).Characters.Item(1).Text = str12;
            }
            else
            {
                document2.Sentences.Item(num2 + 0x25).Characters.Item(1).Text = str12.ToUpper().Replace(".", "");
            }
            if (str21 == "")
            {
                str21 = "Bình thường, valsava +";
                document2.Sentences.Item(num2 + 0x26).Characters.Item(1).Text = str21;
            }
            else
            {
                document2.Sentences.Item(num2 + 0x26).Characters.Item(1).Text = str21.ToUpper().Replace(".", "");
            }
            if (str13 == "")
            {
                str13 = "Bình thường, valsava +";
                document2.Sentences.Item(num2 + 0x29).Characters.Item(1).Text = str13;
            }
            else
            {
                document2.Sentences.Item(num2 + 0x29).Characters.Item(1).Text = str13.ToUpper().Replace(".", "");
            }
            if (str14 == "")
            {
                str14 = "thẳng";
                document2.Sentences.Item(num2 + 0x2a).Characters.Item(1).Text = str14;
            }
            else
            {
                document2.Sentences.Item(num2 + 0x2a).Characters.Item(1).Text = str14.ToUpper().Replace(".", "");
            }
            if (str4 == "")
            {
                str4 = "thẳng";
                document2.Sentences.Item(num2 + 0x2d).Characters.Item(1).Text = str4;
            }
            else
            {
                document2.Sentences.Item(num2 + 0x2d).Characters.Item(1).Text = str4.ToUpper().Replace(".", "");
            }
            if (str15 == "")
            {
                str15 = "Bình thường";
                document2.Sentences.Item(num2 + 0x2e).Characters.Item(1).Text = str15;
            }
            else
            {
                document2.Sentences.Item(num2 + 0x2e).Characters.Item(1).Text = str15.ToUpper().Replace(".", "");
            }
            if (str5 == "")
            {
                str5 = "Bình thường";
                document2.Sentences.Item(num2 + 0x31).Characters.Item(1).Text = str5;
            }
            else
            {
                document2.Sentences.Item(num2 + 0x31).Characters.Item(1).Text = str5.ToUpper().Replace(".", "");
            }
            if (((str16 == "") && (str18 == "")) && (str19 == ""))
            {
                str16 = "Th\x00f4ng tho\x00e1ng";
                document2.Sentences.Item(num2 + 50).Characters.Item(1).Text = str16;
            }
            else
            {
                range = document2.Sentences.Item(num2 + 50).Characters.Item(1);
                str33 = (str19.ToUpper().Replace(".", "") + "," + str16.ToUpper().Replace(".", "") + "," + str18.ToUpper().Replace(".", "")).Trim().Replace(",,", ",");
                if (str33.EndsWith(","))
                {
                    str33 = str33.Substring(0, str33.Length - 1);
                }
                if (str33.StartsWith(","))
                {
                    str33 = str33.Substring(1, str33.Length - 1);
                }
                if (str33.StartsWith(",") && str33.EndsWith(","))
                {
                    str33 = str33.Substring(2, str33.Length - 1);
                }
                range.Text = str33.ToUpper();
            }
            if (((str6 == "") && (str8 == "")) && (str9 == ""))
            {
                str6 = "Th\x00f4ng tho\x00e1ng";
                document2.Sentences.Item(num2 + 0x35).Characters.Item(1).Text = str6;
            }
            else
            {
                range = document2.Sentences.Item(num2 + 0x35).Characters.Item(1);
                str33 = (str9.ToUpper().Replace(".", "") + "," + str6.ToUpper().Replace(".", "") + "," + str8.ToUpper().Replace(".", "")).Trim().Replace(",,", ",");
                if (str33.EndsWith(","))
                {
                    str33 = str33.Substring(0, str33.Length - 1);
                }
                if (str33.StartsWith(","))
                {
                    str33 = str33.Substring(1, str33.Length - 1);
                }
                if (str33.StartsWith(",") && str33.EndsWith(","))
                {
                    str33 = str33.Substring(2, str33.Length - 1);
                }
                range.Text = str33;
            }
            if (str17 == "")
            {
                str17 = "Th\x00f4ng tho\x00e1ng";
                document2.Sentences.Item(num2 + 0x36).Characters.Item(1).Text = str17;
            }
            else
            {
                document2.Sentences.Item(num2 + 0x36).Characters.Item(1).Text = str17.ToUpper().Replace(".", "");
            }
            if (str7 == "")
            {
                str7 = "Th\x00f4ng tho\x00e1ng";
                document2.Sentences.Item(num2 + 0x39).Characters.Item(1).Text = str7;
            }
            else
            {
                document2.Sentences.Item(num2 + 0x39).Characters.Item(1).Text = str7.ToUpper().Replace(".", "");
            }
            if (str22 == "")
            {
                str22 = "gờ v\x00f2i di động tốt, loa v\x00f2i tho\x00e1ng, không u, hố Rosenmuller trống ";
                document2.Sentences.Item(num2 + 0x3a).Characters.Item(1).Text = str22;
            }
            else
            {
                document2.Sentences.Item(num2 + 0x3a).Characters.Item(1).Text = str22.ToUpper().Replace(".", "");
            }
            if (str23 == "")
            {
                str23 = "gờ v\x00f2i di động tốt, loa v\x00f2i tho\x00e1ng, không u, hố Rosenmuller trống ";
                document2.Sentences.Item(num2 + 0x3d).Characters.Item(1).Text = str23;
            }
            else
            {
                document2.Sentences.Item(num2 + 0x3d).Characters.Item(1).Text = str23.ToUpper().Replace(".", "");
            }
            range = document2.Sentences.Item(num2 + 0x3f).Characters.Item(1);
            if (str10 == "")
            {
                str10 = "sạch, thông tho\x00e1ng";
                range.Text = str10;
            }
            else
            {
                range.Text = str10.ToUpper().Replace(".", "");
            }
            range = document2.Sentences.Item(num2 + 0x41).Characters.Item(1);
            if (str11 == "")
            {
                str11 = "Thung lũng thanh môn, xoang l\x00ea trống, sụn phễu, d\x00e2y thanh di động tốt, không u";
                range.Text = str11;
            }
            else
            {
                range.Text = str11.ToUpper().Replace(".", "");
            }
            if (dtSR.Rows.Count > 0)
            {
                document2.Sentences.Item(num2 + 0x43).Characters.Item(1).Text = dtSR.Rows[0][InfoScanResult.SRTOPINION].ToString().ToUpper().Replace(".", "");
                document2.Sentences.Item(num2 + 0x45).Characters.Item(1).Text = dtSR.Rows[0][InfoScanResult.SRTSUGGESTION].ToString().ToUpper().Replace(".", "");
            }

            #endregion

            object obj9 = new object();
            object obj10 = new object();
            Image.GetThumbnailImageAbort abort = new Image.GetThumbnailImageAbort(this.ThumbnailCallback);

            DataTable dtScanPicture = objController.GetData(InfoScanPicture.TABLENAME, true, 5, false, null, param, null);

            if (dtScanPicture != null)
            {
                if (File.Exists(this.ImagePath.Replace("/", @"\")))
                {
                    File.Create(this.ImagePath.Replace("/", @"\"));
                }
                string pictureFile = "";
                string str36 = "";
                string str37 = "";
                string str38 = "";
                string str39 = "";
                for (int k = 0; k < dtScanPicture.Rows.Count; k++)
                {
                    InlineShape shape;
                    string path = string.Concat(new object[] { this.ImagePath, "/I", dtScanPicture.Rows[k]["scpISN"], "C", dtScanPicture.Rows[k][InfoScanPicture.CLRISN], ".jpg" });
                    if (!File.Exists(path))
                    {
                        byte[] buffer = (byte[])dtScanPicture.Rows[k][InfoScanPicture.SCPIMAGE];
                        MemoryStream stream = new MemoryStream(buffer);
                        Image.FromStream(stream).Save(path);
                        stream.Close();
                        stream.Flush();
                    }
                    if (k == 0)
                    {
                        pictureFile = path;
                        shape = class2.ActiveDocument.InlineShapes.New(document2.Sentences.Item(num2 + 0x47).Characters.Item(1));
                        shape.Height = 150f;
                        shape.Width = 200f;
                        shape.Borders.OutsideColor = WdColor.wdColorWhite;
                        shape.Fill.UserPicture(pictureFile);
                        document2.Sentences.Item(num2 + 0x4d).Characters.Item(1).Text = dtScanPicture.Rows[k][InfoScanPicture.SCPNOTE].ToString().Replace(".", "");
                    }
                    else if (k == 1)
                    {
                        str36 = path;
                        shape = class2.ActiveDocument.InlineShapes.New(document2.Sentences.Item(num2 + 0x49).Characters.Item(1));
                        shape.Height = 150f;
                        shape.Width = 200f;
                        shape.Borders.OutsideColor = WdColor.wdColorWhite;
                        shape.Fill.UserPicture(str36);
                        document2.Sentences.Item(num2 + 0x4f).Characters.Item(1).Text = dtScanPicture.Rows[k][InfoScanPicture.SCPNOTE].ToString().Replace(".", "");
                    }
                    else if (k == 2)
                    {
                        str37 = path;
                        shape = class2.ActiveDocument.InlineShapes.New(document2.Sentences.Item(num2 + 0x4b).Characters.Item(1));
                        shape.Height = 150f;
                        shape.Width = 200f;
                        shape.Borders.OutsideColor = WdColor.wdColorWhite;
                        shape.Fill.UserPicture(str37);
                        document2.Sentences.Item(num2 + 0x51).Characters.Item(1).Text = dtScanPicture.Rows[k][InfoScanPicture.SCPNOTE].ToString().Replace(".", "");
                    }
                    else if (k == 3)
                    {
                        str38 = path;
                        shape = class2.ActiveDocument.InlineShapes.New(document2.Sentences.Item(num2 + 0x58).Characters.Item(1));
                        shape.Height = 150f;
                        shape.Width = 200f;
                        shape.Borders.OutsideColor = WdColor.wdColorWhite;
                        shape.Fill.UserPicture(str38);
                        document2.Sentences.Item(num2 + 0x5c).Characters.Item(1).Text = dtScanPicture.Rows[k][InfoScanPicture.SCPNOTE].ToString().Replace(".", "");
                    }
                    else if (k == 4)
                    {
                        str39 = path;
                        shape = class2.ActiveDocument.InlineShapes.New(document2.Sentences.Item(num2 + 90).Characters.Item(1));
                        shape.Height = 150f;
                        shape.Width = 200f;
                        shape.Borders.OutsideColor = WdColor.wdColorWhite;
                        shape.Fill.UserPicture(str39);
                        document2.Sentences.Item(num2 + 0x5e).Characters.Item(1).Text = dtScanPicture.Rows[k][InfoScanPicture.SCPNOTE].ToString().Replace(".", "");
                    }
                }
            }
        }

        private void btLuu_Click(object sender, EventArgs e)
        {
            int num = 2;
            if (this.CheckInputData())
            {
                ArrayList list = new ArrayList();
                ArrayList list2 = new ArrayList();
                int count = this.lbNoiSoi.Items.Count;
                string text = "";
                string str2 = "";
                for (int i = 0; i < count; i++)
                {
                    list.Add(this.lbNoiSoi.Items[i].ToString());
                }
                TransactionManager trans = TransactionManager.ThreadTransactionMgr();

                try
                {
                    trans.BeginTransaction();
                    List<ExpressionObject> paramInnerScan = new List<ExpressionObject>();
                    DataTable dtInnerScan;
                    for (int j = 0; j < list.Count; j++)
                    {
                        paramInnerScan.Clear();
                        paramInnerScan.Add(new ExpressionObject("nscNameChild", list[j].ToString()));
                        paramInnerScan.Add(new ExpressionObject("nscNameLevelThree", list[j].ToString(), ExpressionObject.eSelectOperator.Equal, ExpressionObject.eCombineOperator.Or));
                        dtInnerScan = objController.GetData("vw_InnerScan", paramInnerScan);

                        if (dtInnerScan.Rows.Count == 0)
                            continue;

                        str2 = list[j].ToString();
                        str2 = str2.Substring(str2.IndexOf('(') + 1, 1);
                        if (str2.ToUpper() == "T")
                        {
                            num = 1;
                        }
                        else if (str2.ToUpper() == "P")
                        {
                            num = 2;
                        }
                        if (!(dtInnerScan.Rows[0]["Root3"].ToString() != ""))
                        {
                            goto Label_053B;
                        }
                        list2.Add(dtInnerScan.Rows[0]["nscISNLevelThree"].ToString());
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "167")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtOngTaiNgoaiP.Text;
                                    break;

                                case 1:
                                    text = this.txtOngTaiNgoaiT.Text;
                                    goto Label_01D4;
                            }
                        }
                    Label_01D4:
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "168")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtMangNhiP.Text;
                                    break;

                                case 1:
                                    text = this.txtMangNhiT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "170")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtCuonDuoiP.Text;
                                    break;

                                case 1:
                                    text = this.txtCuonDuoiT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "169")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtVachNganP.Text;
                                    break;

                                case 1:
                                    text = this.txtVachNganT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "171")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtCuonGiuaP.Text;
                                    break;

                                case 1:
                                    text = this.txtCuonGiuaT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "172")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtKheGiuaP.Text;
                                    break;

                                case 1:
                                    text = this.txtKheGiuaT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "173")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtKheTrenP.Text;
                                    break;

                                case 1:
                                    text = this.txtKheTrenT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0]["Root3"].ToString() == "174")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtMomMocP.Text;
                                    break;

                                case 1:
                                    text = this.txtMomMocT.Text;
                                    break;
                            }
                        }

                        if (text != "")
                        {
                            ListDictionary paramSR = new ListDictionary();
                            paramSR.Add(InfoScanResult.CLRISN, this._clrISN);
                            paramSR.Add(InfoScanResult.NSCISN, dtInnerScan.Rows[0]["nscISNLevelThree"].ToString());
                            paramSR.Add(InfoScanResult.SRTSCANOUTLIST, this.tbNoiSoiNgoaiDanhSach.Text.ToString());
                            paramSR.Add(InfoScanResult.SRTOPINION, this.txtCamNghi.Text.ToString());
                            paramSR.Add(InfoScanResult.SRTSUGGESTION, this.txtDeNghi.Text.ToString());

                            paramSR.Add(InfoScanResult.NSCISNROOT, dtInnerScan.Rows[0]["Root3"].ToString());
                            paramSR.Add(InfoScanResult.SRTPOSITIONSTATUS, num); //2: phải l; 1 : trái
                            paramSR.Add(InfoScanResult.SRTSCANLISTSTRING, text);
                            objController.Exec_StoreProc("sp_ScanResult", paramSR);
                        }
                        continue;
                    Label_053B:
                        list2.Add(dtInnerScan.Rows[0]["nscISNChild"].ToString());
                        if (dtInnerScan.Rows[0][InfoInnerScan.NSCISN].ToString() == "85")
                        {
                            text = this.txtHaHong.Text;
                        }
                        if (dtInnerScan.Rows[0][InfoInnerScan.NSCISN].ToString() == "3")
                        {
                            switch (num)
                            {
                                case 2:
                                    text = this.txtVomHongP.Text;
                                    break;

                                case 1:
                                    text = this.txtVomHongT.Text;
                                    break;
                            }
                        }
                        if (dtInnerScan.Rows[0][InfoInnerScan.NSCISN].ToString() == "4")
                        {
                            text = this.txtThanhQuan.Text;
                        }

                        if (text != "")
                        {
                            ListDictionary paramSR = new ListDictionary();
                            paramSR.Add(InfoScanResult.CLRISN, this._clrISN);
                            paramSR.Add(InfoScanResult.NSCISN, dtInnerScan.Rows[0]["nscISNChild"].ToString());
                            paramSR.Add(InfoScanResult.SRTSCANOUTLIST, this.tbNoiSoiNgoaiDanhSach.Text.ToString());
                            paramSR.Add(InfoScanResult.SRTOPINION, this.txtCamNghi.Text.ToString());
                            paramSR.Add(InfoScanResult.SRTSUGGESTION, this.txtDeNghi.Text.ToString());

                            paramSR.Add(InfoScanResult.NSCISNROOT, dtInnerScan.Rows[0][InfoInnerScan.NSCISN].ToString());
                            paramSR.Add(InfoScanResult.SRTPOSITIONSTATUS, num); //2: phải l; 1 : trái
                            paramSR.Add(InfoScanResult.SRTSCANLISTSTRING, text);
                            objController.Exec_StoreProc("sp_ScanResult", paramSR);
                        }
                    }
                    this.NoiSoiNgoaiDS();

                    trans.CommitTransaction();
                    MessageBox.Show("Nội soi đã được lưu", "Lưu Nội Soi", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.btLuu.Enabled = false;
                    this.btHinhAnh.Enabled = true;
                    list.Clear();
                    list2.Clear();
                    count = 0;

                }
                catch (Exception ex)
                {
                    trans.RollbackTransaction();
                    Class.ShowException(ex);
                }
            }
        }

        private void btRemove_Click(object sender, EventArgs e)
        {
            this.lbNoiSoi_DoubleClick(sender, e);
            this.NoiSoiCheck();
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btThoát_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private bool CheckInputData()
        {
            for (int i = 0; i < this.lbNoiSoi.Items.Count; i++)
            {
                for (int j = 0; j < this.lbNoiSoi.Items.Count; j++)
                {
                    if (this.lbNoiSoi.Items[j].ToString() == "")
                    {
                        this.lbNoiSoi.Items.Remove(this.lbNoiSoi.Items[j]);
                    }
                }
            }
            return true;
        }

        private void frmNoiSoi_Load(object sender, EventArgs e)
        {
            this.LoadCayNoiSoi();
            if (this._Insert)
            {
                this.btLuu.Enabled = true;
                this.btCapNhat.Enabled = false;
                this.btHinhAnh.Enabled = false;
            }
            else
            {
                this.btLuu.Enabled = false;
                this.btCapNhat.Enabled = true;
                this.btHinhAnh.Enabled = true;
                List<ExpressionObject> param = new List<ExpressionObject>();
                param.Add(new ExpressionObject(InfoScanResult.CLRISN, this._clrISN));
                ListDictionary orderby = new ListDictionary();
                orderby.Add(InfoScanResult.NSCISNROOT, "asc");
                orderby.Add(InfoScanResult.SRTPOSITIONSTATUS, "asc");
                DataTable dtSR = objController.GetData("vw_ScanResult_InnerScan", param, orderby);

                if (dtSR != null && dtSR.Rows.Count > 0)
                {
                    this.lbNoiSoi.Items.Clear();
                    for (int i = 0; i < dtSR.Rows.Count; i++)
                    {
                        if (dtSR.Rows[i][InfoInnerScan.NSCNAME].ToString() != "")
                        {
                            this.lbNoiSoi.Items.Add(dtSR.Rows[i][InfoInnerScan.NSCNAME].ToString());
                        }
                        if (dtSR.Rows[i][InfoInnerScan.NSCISNROOT].ToString() == "167")
                        {
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "2") && (this.txtOngTaiNgoaiP.Text == ""))
                            {
                                this.txtOngTaiNgoaiP.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "1") && (this.txtOngTaiNgoaiT.Text == ""))
                            {
                                this.txtOngTaiNgoaiT.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                        }
                        if (dtSR.Rows[i][InfoInnerScan.NSCISNROOT].ToString() == "168")
                        {
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "2") && (this.txtMangNhiP.Text == ""))
                            {
                                this.txtMangNhiP.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "1") && (this.txtMangNhiT.Text == ""))
                            {
                                this.txtMangNhiT.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                        }
                        if (dtSR.Rows[i][InfoInnerScan.NSCISNROOT].ToString() == "170")
                        {
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "2") && (this.txtCuonDuoiP.Text == ""))
                            {
                                this.txtCuonDuoiP.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "1") && (this.txtCuonDuoiT.Text == ""))
                            {
                                this.txtCuonDuoiT.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                        }
                        if (dtSR.Rows[i][InfoInnerScan.NSCISNROOT].ToString() == "169")
                        {
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "2") && (this.txtVachNganP.Text == ""))
                            {
                                this.txtVachNganP.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "1") && (this.txtVachNganT.Text == ""))
                            {
                                this.txtVachNganT.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                        }
                        if (dtSR.Rows[i][InfoInnerScan.NSCISNROOT].ToString() == "171")
                        {
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "2") && (this.txtCuonGiuaP.Text == ""))
                            {
                                this.txtCuonGiuaP.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "1") && (this.txtCuonGiuaT.Text == ""))
                            {
                                this.txtCuonGiuaT.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                        }
                        if (dtSR.Rows[i][InfoInnerScan.NSCISNROOT].ToString() == "172")
                        {
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "2") && (this.txtKheGiuaP.Text == ""))
                            {
                                this.txtKheGiuaP.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "1") && (this.txtKheGiuaT.Text == ""))
                            {
                                this.txtKheGiuaT.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                        }
                        if (dtSR.Rows[i][InfoInnerScan.NSCISNROOT].ToString() == "173")
                        {
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "2") && (this.txtKheTrenP.Text == ""))
                            {
                                this.txtKheTrenP.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "1") && (this.txtKheTrenT.Text == ""))
                            {
                                this.txtKheTrenT.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                        }
                        if (dtSR.Rows[i][InfoInnerScan.NSCISNROOT].ToString() == "174")
                        {
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "2") && (this.txtMomMocP.Text == ""))
                            {
                                this.txtMomMocP.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "1") && (this.txtMomMocT.Text == ""))
                            {
                                this.txtMomMocT.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                        }
                        if (dtSR.Rows[i][InfoInnerScan.NSCISNROOT].ToString() == "3")
                        {
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "2") && (this.txtVomHongP.Text == ""))
                            {
                                this.txtVomHongP.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                            if ((dtSR.Rows[i][InfoScanResult.SRTPOSITIONSTATUS].ToString() == "1") && (this.txtVomHongT.Text == ""))
                            {
                                this.txtVomHongT.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                            }
                        }
                        if ((dtSR.Rows[i][InfoInnerScan.NSCISNROOT].ToString() == "85") && (this.txtHaHong.Text == ""))
                        {
                            this.txtHaHong.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                        }
                        if ((dtSR.Rows[i][InfoInnerScan.NSCISNROOT].ToString() == "4") && (this.txtThanhQuan.Text == ""))
                        {
                            this.txtThanhQuan.Text = dtSR.Rows[i][InfoScanResult.SRTSCANLISTSTRING].ToString();
                        }
                        if (dtSR.Rows[0][InfoScanResult.SRTSCANLISTSTRING].ToString() == "")
                        {
                            this.NoiSoiCheck();
                        }
                    }
                    this.tbNoiSoiNgoaiDanhSach.Text = dtSR.Rows[0][InfoScanResult.SRTSCANOUTLIST].ToString();
                    this.txtCamNghi.Text = dtSR.Rows[0][InfoScanResult.SRTOPINION].ToString();
                    this.txtDeNghi.Text = dtSR.Rows[0][InfoScanResult.SRTSUGGESTION].ToString();
                }
            }
        }

        private void insertChildNode(string strName)
        {
            this.node.Nodes.Add(strName);
        }

        private void insertParentNode(string strName)
        {
            this.node = new TreeNode(strName);
        }

        private void lbNoiSoi_DoubleClick(object sender, EventArgs e)
        {
            this.NoiSoiCheckRemove(this.lbNoiSoi.SelectedItem.ToString());
            this.lbNoiSoi.Items.Remove(this.lbNoiSoi.SelectedItem);
        }

        private void lbNoiSoi_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.toolTip1.SetToolTip(this.lbNoiSoi, this.lbNoiSoi.Text.ToString());
        }

        private void LoadCayNoiSoi()
        {
            ArrayList list = new ArrayList();
            ArrayList list2 = new ArrayList();

            ArrayList arrCoIS = new ArrayList();
            arrCoIS.Add(InfoInnerScan.NSCISN);
            arrCoIS.Add(InfoInnerScan.NSCNAME);
            ListDictionary orderbyIS = new ListDictionary();
            orderbyIS.Add(InfoInnerScan.NSCNAME, "asc");
            DataTable dtIS = objController.GetData("vw_InnerScan", true, arrCoIS, null, orderbyIS);

            if (dtIS != null)
            {
                for (int i = 0; i < dtIS.Rows.Count; i++)
                {
                    list.Add(dtIS.Rows[i][0].ToString());
                    list2.Add(dtIS.Rows[i][1].ToString());
                }

                ArrayList arrCoIS2 = new ArrayList();
                arrCoIS2.Add(InfoInnerScan.NSCISN);
                arrCoIS2.Add(InfoInnerScan.NSCNAME);
                arrCoIS2.Add("nscISNChild");
                arrCoIS2.Add("nscNameChild");
                arrCoIS2.Add("Root1");
                arrCoIS2.Add("Root2");
                arrCoIS2.Add("Root3");
                ListDictionary orderbyIS2 = new ListDictionary();
                orderbyIS2.Add("nscNameChild", "asc");
                DataTable dtIS2;

                ArrayList arrCoIS3 = new ArrayList();
                arrCoIS3.Add("nscISNLevelThree");
                arrCoIS3.Add("nscNameLevelThree");
                ListDictionary orderbyIS3 = new ListDictionary();
                orderbyIS3.Add("nscNameLevelThree", "asc");
                DataTable dtIS3;

                List<ExpressionObject> paramIS = new List<ExpressionObject>();
                for (int j = 0; j < list.Count; j++)
                {   
                    this.insertParentNode(list2[j].ToString());
                    paramIS.Clear();
                    paramIS.Add(new ExpressionObject(InfoInnerScan.NSCISN, list[j].ToString()));
                    dtIS2 = objController.GetData("vw_InnerScan", true, arrCoIS2, paramIS, orderbyIS2);

                    for (int k = 0; k < dtIS2.Rows.Count; k++)
                    {
                        this.insertChildNode(dtIS2.Rows[k]["nscNameChild"].ToString());
                        if (dtIS2.Rows[k]["Root3"].ToString() != "")
                        {
                            paramIS.Clear();
                            paramIS.Add(new ExpressionObject("nscISNLevelThree", "is not null", ExpressionObject.eSelectOperator.None));
                            paramIS.Add(new ExpressionObject("nscISNChild", dtIS2.Rows[k]["Root3"]));
                            dtIS3 = objController.GetData("vw_InnerScan", false, arrCoIS3, paramIS, orderbyIS3);

                            for (int m = 0; m < dtIS3.Rows.Count; m++)
                            {
                                this.node.Nodes[k].Nodes.Add(dtIS3.Rows[m]["nscNameLevelThree"].ToString());
                            }
                        }
                    }
                    this.tvNoiSoi.Nodes.Add(this.node);
                }
            }
        }

        private void NoiSoiCheck()
        {
            ArrayList list = new ArrayList();
            ArrayList list2 = new ArrayList();
            int count = this.lbNoiSoi.Items.Count;
            for (int i = 0; i < count; i++)
            {
                if (this.lbNoiSoi.Items[i].ToString() != "")
                {
                    list.Add(this.lbNoiSoi.Items[i].ToString());
                }
            }

            ArrayList arrCoInnerScan = new ArrayList();
            arrCoInnerScan.Add(InfoInnerScan.NSCISN);
            arrCoInnerScan.Add(InfoInnerScan.NSCISNROOT);
            arrCoInnerScan.Add(InfoInnerScan.NSCNAME);
            List<ExpressionObject> param = new List<ExpressionObject>();
            for (int j = 0; j < list.Count; j++)
            {
                param.Clear();
                param.Add(new ExpressionObject(InfoInnerScan.NSCNAME, list[j].ToString()));
                DataTable dtInnerScan = objController.GetData(InfoInnerScan.TABLENAME, arrCoInnerScan, param);

                string str = list[j].ToString();
                str = str.Substring(str.IndexOf('(') + 1, 1);
                if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "167")
                {
                    if (str.ToUpper() == "T")
                    {
                        this.txtOngTaiNgoaiT.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString());
                        if (this.txtOngTaiNgoaiT.Text == "")
                        {
                            this.txtOngTaiNgoaiT.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtOngTaiNgoaiT.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtOngTaiNgoaiT.Text = this.txtOngTaiNgoaiT.Text;
                        }
                        else
                        {
                            this.txtOngTaiNgoaiT.Text = this.txtOngTaiNgoaiT.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                    else if (str.ToUpper() == "P")
                    {
                        if (this.txtOngTaiNgoaiP.Text == "")
                        {
                            this.txtOngTaiNgoaiP.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtOngTaiNgoaiP.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtOngTaiNgoaiP.Text = this.txtOngTaiNgoaiP.Text;
                        }
                        else
                        {
                            this.txtOngTaiNgoaiP.Text = this.txtOngTaiNgoaiP.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                }
                if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "168")
                {
                    if (str.ToUpper() == "T")
                    {
                        if (this.txtMangNhiT.Text == "")
                        {
                            this.txtMangNhiT.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtMangNhiT.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtMangNhiT.Text = this.txtMangNhiT.Text;
                        }
                        else
                        {
                            this.txtMangNhiT.Text = this.txtMangNhiT.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                    if (str.ToUpper() == "P")
                    {
                        if (this.txtMangNhiP.Text == "")
                        {
                            this.txtMangNhiP.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtMangNhiP.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtMangNhiP.Text = this.txtMangNhiP.Text;
                        }
                        else
                        {
                            this.txtMangNhiP.Text = this.txtMangNhiP.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                }
                if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "169")
                {
                    if (str.ToUpper() == "T")
                    {
                        if (this.txtVachNganT.Text == "")
                        {
                            this.txtVachNganT.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtVachNganT.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtVachNganT.Text = this.txtVachNganT.Text;
                        }
                        else
                        {
                            this.txtVachNganT.Text = this.txtVachNganT.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                    if (str.ToUpper() == "P")
                    {
                        if (this.txtVachNganP.Text == "")
                        {
                            this.txtVachNganP.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtVachNganP.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtVachNganP.Text = this.txtVachNganP.Text;
                        }
                        else
                        {
                            this.txtVachNganP.Text = this.txtVachNganP.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                }
                if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "170")
                {
                    if (str.ToUpper() == "T")
                    {
                        if (this.txtCuonDuoiT.Text == "")
                        {
                            this.txtCuonDuoiT.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtCuonDuoiT.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtCuonDuoiT.Text = this.txtCuonDuoiT.Text;
                        }
                        else
                        {
                            this.txtCuonDuoiT.Text = this.txtCuonDuoiT.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                    if (str.ToUpper() == "P")
                    {
                        if (this.txtCuonDuoiP.Text == "")
                        {
                            this.txtCuonDuoiP.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtCuonDuoiP.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtCuonDuoiP.Text = this.txtCuonDuoiP.Text;
                        }
                        else
                        {
                            this.txtCuonDuoiP.Text = this.txtCuonDuoiP.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                }
                if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "171")
                {
                    if (str.ToUpper() == "T")
                    {
                        if (this.txtCuonGiuaT.Text == "")
                        {
                            this.txtCuonGiuaT.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtCuonGiuaT.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtCuonGiuaT.Text = this.txtCuonGiuaT.Text;
                        }
                        else
                        {
                            this.txtCuonGiuaT.Text = this.txtCuonGiuaT.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                    if (str.ToUpper() == "P")
                    {
                        if (this.txtCuonGiuaP.Text == "")
                        {
                            this.txtCuonGiuaP.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtCuonGiuaP.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtCuonGiuaP.Text = this.txtCuonGiuaP.Text;
                        }
                        else
                        {
                            this.txtCuonGiuaP.Text = this.txtCuonGiuaP.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                }
                if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "172")
                {
                    if (str.ToUpper() == "T")
                    {
                        if (this.txtKheGiuaT.Text == "")
                        {
                            this.txtKheGiuaT.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtKheGiuaT.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtKheGiuaT.Text = this.txtKheGiuaT.Text;
                        }
                        else
                        {
                            this.txtKheGiuaT.Text = this.txtKheGiuaT.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                    if (str.ToUpper() == "P")
                    {
                        if (this.txtKheGiuaP.Text == "")
                        {
                            this.txtKheGiuaP.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtKheGiuaP.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtKheGiuaP.Text = this.txtKheGiuaP.Text;
                        }
                        else
                        {
                            this.txtKheGiuaP.Text = this.txtKheGiuaP.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                }
                if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "173")
                {
                    if (str.ToUpper() == "T")
                    {
                        if (this.txtKheTrenT.Text == "")
                        {
                            this.txtKheTrenT.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtKheTrenT.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtKheTrenT.Text = this.txtKheTrenT.Text;
                        }
                        else
                        {
                            this.txtKheTrenT.Text = this.txtKheTrenT.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                    if (str.ToUpper() == "P")
                    {
                        if (this.txtKheTrenP.Text == "")
                        {
                            this.txtKheTrenP.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtKheTrenP.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtKheTrenP.Text = this.txtKheTrenP.Text;
                        }
                        else
                        {
                            this.txtKheTrenP.Text = this.txtKheTrenP.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                }
                if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "174")
                {
                    if (str.ToUpper() == "T")
                    {
                        if (this.txtMomMocT.Text == "")
                        {
                            this.txtMomMocT.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtMomMocT.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtMomMocT.Text = this.txtMomMocT.Text;
                        }
                        else
                        {
                            this.txtMomMocT.Text = this.txtMomMocT.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                    if (str.ToUpper() == "P")
                    {
                        if (this.txtMomMocP.Text == "")
                        {
                            this.txtMomMocP.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtMomMocP.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtMomMocP.Text = this.txtMomMocP.Text;
                        }
                        else
                        {
                            this.txtMomMocP.Text = this.txtMomMocP.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                }
                if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "85")
                {
                    if (this.txtHaHong.Text == "")
                    {
                        this.txtHaHong.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                    }
                    else if (this.txtHaHong.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                    {
                        this.txtHaHong.Text = this.txtHaHong.Text;
                    }
                    else
                    {
                        this.txtHaHong.Text = this.txtHaHong.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                    }
                }
                if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "3")
                {
                    if (str.ToUpper() == "T")
                    {
                        if (this.txtVomHongT.Text == "")
                        {
                            this.txtVomHongT.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtVomHongT.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtVomHongT.Text = this.txtVomHongT.Text;
                        }
                        else
                        {
                            this.txtVomHongT.Text = this.txtVomHongT.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                    if (str.ToUpper() == "P")
                    {
                        if (this.txtVomHongP.Text == "")
                        {
                            this.txtVomHongP.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                        else if (this.txtVomHongP.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                        {
                            this.txtVomHongP.Text = this.txtVomHongP.Text;
                        }
                        else
                        {
                            this.txtVomHongP.Text = this.txtVomHongP.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                        }
                    }
                }
                if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "4")
                {
                    if (this.txtThanhQuan.Text == "")
                    {
                        this.txtThanhQuan.Text = dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                    }
                    else if (this.txtThanhQuan.Text.IndexOf(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString()) >= 0)
                    {
                        this.txtThanhQuan.Text = this.txtThanhQuan.Text;
                    }
                    else
                    {
                        this.txtThanhQuan.Text = this.txtThanhQuan.Text + "," + dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString();
                    }
                }
            }
        }

        private void NoiSoiCheckRemove(string TenNoiSoi)
        {
            ArrayList arrColumn = new ArrayList();
            arrColumn.Add(InfoInnerScan.NSCISN);
            arrColumn.Add(InfoInnerScan.NSCISNROOT);
            arrColumn.Add(InfoInnerScan.NSCNAME);

            List<ExpressionObject> param = new List<ExpressionObject>();
            param.Add(new ExpressionObject(InfoInnerScan.NSCNAME, TenNoiSoi));
            DataTable dtInnerScan = objController.GetData(InfoInnerScan.TABLENAME, arrColumn, param);

            string str = TenNoiSoi;
            str = str.Substring(str.IndexOf('(') + 1, 1);
            if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "167")
            {
                if (str.ToUpper() == "T")
                {
                    this.txtOngTaiNgoaiT.Text = this.txtOngTaiNgoaiT.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtOngTaiNgoaiT.Text = this.txtOngTaiNgoaiT.Text.Trim();
                    this.txtOngTaiNgoaiT.Text = this.txtOngTaiNgoaiT.Text.Replace(",,", ",");
                    if (this.txtOngTaiNgoaiT.Text.EndsWith(","))
                    {
                        this.txtOngTaiNgoaiT.Text = this.txtOngTaiNgoaiT.Text.Substring(0, this.txtOngTaiNgoaiT.Text.Length - 1);
                    }
                    if (this.txtOngTaiNgoaiT.Text.StartsWith(","))
                    {
                        this.txtOngTaiNgoaiT.Text = this.txtOngTaiNgoaiT.Text.Substring(1, this.txtOngTaiNgoaiT.Text.Length - 1);
                    }
                    if (this.txtOngTaiNgoaiT.Text.StartsWith(",") && this.txtOngTaiNgoaiT.Text.EndsWith(","))
                    {
                        this.txtOngTaiNgoaiT.Text = this.txtOngTaiNgoaiT.Text.Substring(2, this.txtOngTaiNgoaiT.Text.Length - 1);
                    }
                }
                else if (str.ToUpper() == "P")
                {
                    this.txtOngTaiNgoaiP.Text = this.txtOngTaiNgoaiP.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtOngTaiNgoaiP.Text = this.txtOngTaiNgoaiP.Text.Trim();
                    this.txtOngTaiNgoaiP.Text = this.txtOngTaiNgoaiP.Text.Replace(",,", ",");
                    if (this.txtOngTaiNgoaiP.Text.EndsWith(","))
                    {
                        this.txtOngTaiNgoaiP.Text = this.txtOngTaiNgoaiP.Text.Substring(0, this.txtOngTaiNgoaiP.Text.Length - 1);
                    }
                    if (this.txtOngTaiNgoaiP.Text.StartsWith(","))
                    {
                        this.txtOngTaiNgoaiP.Text = this.txtOngTaiNgoaiP.Text.Substring(1, this.txtOngTaiNgoaiP.Text.Length - 1);
                    }
                    if (this.txtOngTaiNgoaiP.Text.StartsWith(",") && this.txtOngTaiNgoaiP.Text.EndsWith(","))
                    {
                        this.txtOngTaiNgoaiP.Text = this.txtOngTaiNgoaiP.Text.Substring(2, this.txtOngTaiNgoaiP.Text.Length - 1);
                    }
                }
            }
            if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "168")
            {
                if (str.ToUpper() == "T")
                {
                    this.txtMangNhiT.Text = this.txtMangNhiT.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtMangNhiT.Text = this.txtMangNhiT.Text.Trim();
                    this.txtMangNhiT.Text = this.txtMangNhiT.Text.Replace(",,", ",");
                    if (this.txtMangNhiT.Text.EndsWith(","))
                    {
                        this.txtMangNhiT.Text = this.txtMangNhiT.Text.Substring(0, this.txtMangNhiT.Text.Length - 1);
                    }
                    if (this.txtMangNhiT.Text.StartsWith(","))
                    {
                        this.txtMangNhiT.Text = this.txtMangNhiT.Text.Substring(1, this.txtMangNhiT.Text.Length - 1);
                    }
                    if (this.txtMangNhiT.Text.StartsWith(",") && this.txtMangNhiT.Text.EndsWith(","))
                    {
                        this.txtMangNhiT.Text = this.txtMangNhiT.Text.Substring(2, this.txtMangNhiT.Text.Length - 1);
                    }
                }
                if (str.ToUpper() == "P")
                {
                    this.txtMangNhiP.Text = this.txtMangNhiP.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtMangNhiP.Text = this.txtMangNhiP.Text.Trim();
                    this.txtMangNhiP.Text = this.txtMangNhiP.Text.Replace(",,", ",");
                    if (this.txtMangNhiP.Text.EndsWith(","))
                    {
                        this.txtMangNhiP.Text = this.txtMangNhiP.Text.Substring(0, this.txtMangNhiP.Text.Length - 1);
                    }
                    if (this.txtMangNhiP.Text.StartsWith(","))
                    {
                        this.txtMangNhiP.Text = this.txtMangNhiP.Text.Substring(1, this.txtMangNhiP.Text.Length - 1);
                    }
                    if (this.txtMangNhiP.Text.StartsWith(",") && this.txtMangNhiP.Text.EndsWith(","))
                    {
                        this.txtMangNhiP.Text = this.txtMangNhiP.Text.Substring(2, this.txtMangNhiP.Text.Length - 1);
                    }
                }
            }
            if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "169")
            {
                if (str.ToUpper() == "T")
                {
                    this.txtVachNganT.Text = this.txtVachNganT.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtVachNganT.Text = this.txtVachNganT.Text.Trim();
                    this.txtVachNganT.Text = this.txtVachNganT.Text.Replace(",,", ",");
                    if (this.txtVachNganT.Text.EndsWith(","))
                    {
                        this.txtVachNganT.Text = this.txtVachNganT.Text.Substring(0, this.txtVachNganT.Text.Length - 1);
                    }
                    if (this.txtVachNganT.Text.StartsWith(","))
                    {
                        this.txtVachNganT.Text = this.txtVachNganT.Text.Substring(1, this.txtVachNganT.Text.Length - 1);
                    }
                    if (this.txtVachNganT.Text.StartsWith(",") && this.txtVachNganT.Text.EndsWith(","))
                    {
                        this.txtVachNganT.Text = this.txtVachNganT.Text.Substring(2, this.txtVachNganT.Text.Length - 1);
                    }
                }
                if (str.ToUpper() == "P")
                {
                    this.txtVachNganP.Text = this.txtVachNganP.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtVachNganP.Text = this.txtVachNganP.Text.Trim();
                    this.txtVachNganP.Text = this.txtVachNganP.Text.Replace(",,", ",");
                    if (this.txtVachNganP.Text.EndsWith(","))
                    {
                        this.txtVachNganP.Text = this.txtVachNganP.Text.Substring(0, this.txtVachNganP.Text.Length - 1);
                    }
                    if (this.txtVachNganP.Text.StartsWith(","))
                    {
                        this.txtVachNganP.Text = this.txtVachNganP.Text.Substring(1, this.txtVachNganP.Text.Length - 1);
                    }
                    if (this.txtVachNganP.Text.StartsWith(",") && this.txtVachNganP.Text.EndsWith(","))
                    {
                        this.txtVachNganP.Text = this.txtVachNganP.Text.Substring(2, this.txtVachNganP.Text.Length - 1);
                    }
                }
            }
            if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "170")
            {
                if (str.ToUpper() == "T")
                {
                    this.txtCuonDuoiT.Text = this.txtCuonDuoiT.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtCuonDuoiT.Text = this.txtCuonDuoiT.Text.Trim();
                    this.txtCuonDuoiT.Text = this.txtCuonDuoiT.Text.Replace(",,", ",");
                    if (this.txtCuonDuoiT.Text.EndsWith(","))
                    {
                        this.txtCuonDuoiT.Text = this.txtCuonDuoiT.Text.Substring(0, this.txtCuonDuoiT.Text.Length - 1);
                    }
                    if (this.txtCuonDuoiT.Text.StartsWith(","))
                    {
                        this.txtCuonDuoiT.Text = this.txtCuonDuoiT.Text.Substring(1, this.txtCuonDuoiT.Text.Length - 1);
                    }
                    if (this.txtCuonDuoiT.Text.StartsWith(",") && this.txtCuonDuoiT.Text.EndsWith(","))
                    {
                        this.txtCuonDuoiT.Text = this.txtCuonDuoiT.Text.Substring(2, this.txtCuonDuoiT.Text.Length - 1);
                    }
                }
                if (str.ToUpper() == "P")
                {
                    this.txtCuonDuoiP.Text = this.txtCuonDuoiP.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtCuonDuoiP.Text = this.txtCuonDuoiP.Text.Trim();
                    this.txtCuonDuoiP.Text = this.txtCuonDuoiP.Text.Replace(",,", ",");
                    if (this.txtCuonDuoiP.Text.EndsWith(","))
                    {
                        this.txtCuonDuoiP.Text = this.txtCuonDuoiP.Text.Substring(0, this.txtCuonDuoiP.Text.Length - 1);
                    }
                    if (this.txtCuonDuoiT.Text.StartsWith(","))
                    {
                        this.txtCuonDuoiP.Text = this.txtCuonDuoiP.Text.Substring(1, this.txtCuonDuoiP.Text.Length - 1);
                    }
                    if (this.txtCuonDuoiP.Text.StartsWith(",") && this.txtCuonDuoiP.Text.EndsWith(","))
                    {
                        this.txtCuonDuoiP.Text = this.txtCuonDuoiP.Text.Substring(2, this.txtCuonDuoiP.Text.Length - 1);
                    }
                }
            }
            if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "171")
            {
                if (str.ToUpper() == "T")
                {
                    this.txtCuonGiuaT.Text = this.txtCuonGiuaT.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtCuonGiuaT.Text = this.txtCuonGiuaT.Text.Trim();
                    this.txtCuonGiuaT.Text = this.txtCuonGiuaT.Text.Replace(",,", ",");
                    if (this.txtCuonGiuaT.Text.EndsWith(","))
                    {
                        this.txtCuonGiuaT.Text = this.txtCuonGiuaT.Text.Substring(0, this.txtCuonGiuaT.Text.Length - 1);
                    }
                    if (this.txtCuonGiuaT.Text.StartsWith(","))
                    {
                        this.txtCuonGiuaT.Text = this.txtCuonGiuaT.Text.Substring(1, this.txtCuonGiuaT.Text.Length - 1);
                    }
                    if (this.txtCuonGiuaT.Text.StartsWith(",") && this.txtCuonGiuaT.Text.EndsWith(","))
                    {
                        this.txtCuonGiuaT.Text = this.txtCuonGiuaT.Text.Substring(2, this.txtCuonGiuaT.Text.Length - 1);
                    }
                }
                if (str.ToUpper() == "P")
                {
                    this.txtCuonGiuaP.Text = this.txtCuonGiuaP.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtCuonGiuaP.Text = this.txtCuonGiuaP.Text.Trim();
                    this.txtCuonGiuaP.Text = this.txtCuonGiuaP.Text.Replace(",,", ",");
                    if (this.txtCuonGiuaP.Text.EndsWith(","))
                    {
                        this.txtCuonGiuaP.Text = this.txtCuonGiuaP.Text.Substring(0, this.txtCuonGiuaP.Text.Length - 1);
                    }
                    if (this.txtCuonGiuaP.Text.StartsWith(","))
                    {
                        this.txtCuonGiuaP.Text = this.txtCuonGiuaP.Text.Substring(1, this.txtCuonGiuaP.Text.Length - 1);
                    }
                    if (this.txtCuonGiuaP.Text.StartsWith(",") && this.txtCuonGiuaP.Text.EndsWith(","))
                    {
                        this.txtCuonGiuaP.Text = this.txtCuonGiuaP.Text.Substring(2, this.txtCuonGiuaP.Text.Length - 1);
                    }
                }
            }
            if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "172")
            {
                if (str.ToUpper() == "T")
                {
                    this.txtKheGiuaT.Text = this.txtKheGiuaT.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtKheGiuaT.Text = this.txtKheGiuaT.Text.Trim();
                    this.txtKheGiuaT.Text = this.txtKheGiuaT.Text.Replace(",,", ",");
                    if (this.txtKheGiuaT.Text.EndsWith(","))
                    {
                        this.txtKheGiuaT.Text = this.txtKheGiuaT.Text.Substring(0, this.txtKheGiuaT.Text.Length - 1);
                    }
                    if (this.txtKheGiuaT.Text.StartsWith(","))
                    {
                        this.txtKheGiuaT.Text = this.txtKheGiuaT.Text.Substring(1, this.txtKheGiuaT.Text.Length - 1);
                    }
                    if (this.txtKheGiuaT.Text.StartsWith(",") && this.txtKheGiuaT.Text.EndsWith(","))
                    {
                        this.txtKheGiuaT.Text = this.txtKheGiuaT.Text.Substring(2, this.txtKheGiuaT.Text.Length - 1);
                    }
                }
                if (str.ToUpper() == "P")
                {
                    this.txtKheGiuaP.Text = this.txtKheGiuaP.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtKheGiuaP.Text = this.txtKheGiuaP.Text.Trim();
                    this.txtKheGiuaP.Text = this.txtKheGiuaP.Text.Replace(",,", ",");
                    if (this.txtKheGiuaP.Text.EndsWith(","))
                    {
                        this.txtKheGiuaP.Text = this.txtKheGiuaP.Text.Substring(0, this.txtKheGiuaP.Text.Length - 1);
                    }
                    if (this.txtKheGiuaP.Text.StartsWith(","))
                    {
                        this.txtKheGiuaP.Text = this.txtKheGiuaP.Text.Substring(1, this.txtKheGiuaP.Text.Length - 1);
                    }
                    if (this.txtKheGiuaP.Text.StartsWith(",") && this.txtKheGiuaP.Text.EndsWith(","))
                    {
                        this.txtKheGiuaP.Text = this.txtKheGiuaP.Text.Substring(2, this.txtKheGiuaP.Text.Length - 1);
                    }
                }
            }
            if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "173")
            {
                if (str.ToUpper() == "T")
                {
                    this.txtKheTrenT.Text = this.txtKheTrenT.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtKheTrenT.Text = this.txtKheTrenT.Text.Trim();
                    this.txtKheTrenT.Text = this.txtKheTrenT.Text.Replace(",,", ",");
                    if (this.txtKheTrenT.Text.EndsWith(","))
                    {
                        this.txtKheTrenT.Text = this.txtKheTrenT.Text.Substring(0, this.txtKheTrenT.Text.Length - 1);
                    }
                    if (this.txtKheTrenT.Text.StartsWith(","))
                    {
                        this.txtKheTrenT.Text = this.txtKheTrenT.Text.Substring(1, this.txtKheTrenT.Text.Length - 1);
                    }
                    if (this.txtKheTrenT.Text.StartsWith(",") && this.txtKheTrenT.Text.EndsWith(","))
                    {
                        this.txtKheTrenT.Text = this.txtKheTrenT.Text.Substring(2, this.txtKheTrenT.Text.Length - 1);
                    }
                }
                if (str.ToUpper() == "P")
                {
                    this.txtKheTrenP.Text = this.txtKheTrenP.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtKheTrenP.Text = this.txtKheTrenP.Text.Trim();
                    this.txtKheTrenP.Text = this.txtKheTrenP.Text.Replace(",,", ",");
                    if (this.txtKheTrenP.Text.EndsWith(","))
                    {
                        this.txtKheTrenP.Text = this.txtKheTrenP.Text.Substring(0, this.txtKheTrenP.Text.Length - 1);
                    }
                    if (this.txtKheTrenP.Text.StartsWith(","))
                    {
                        this.txtKheTrenP.Text = this.txtKheTrenP.Text.Substring(1, this.txtKheTrenP.Text.Length - 1);
                    }
                    if (this.txtKheTrenP.Text.StartsWith(",") && this.txtKheTrenP.Text.EndsWith(","))
                    {
                        this.txtKheTrenP.Text = this.txtKheTrenP.Text.Substring(2, this.txtKheTrenP.Text.Length - 1);
                    }
                }
            }
            if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "174")
            {
                if (str.ToUpper() == "T")
                {
                    this.txtMomMocT.Text = this.txtMomMocT.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtMomMocT.Text = this.txtMomMocT.Text.Trim();
                    this.txtMomMocT.Text = this.txtMomMocT.Text.Replace(",,", ",");
                    if (this.txtMomMocT.Text.EndsWith(","))
                    {
                        this.txtMomMocT.Text = this.txtMomMocT.Text.Substring(0, this.txtMomMocT.Text.Length - 1);
                    }
                    if (this.txtMomMocT.Text.StartsWith(","))
                    {
                        this.txtMomMocT.Text = this.txtMomMocT.Text.Substring(1, this.txtMomMocT.Text.Length - 1);
                    }
                    if (this.txtMomMocT.Text.StartsWith(",") && this.txtMomMocT.Text.EndsWith(","))
                    {
                        this.txtMomMocT.Text = this.txtMomMocT.Text.Substring(2, this.txtMomMocT.Text.Length - 1);
                    }
                }
                if (str.ToUpper() == "P")
                {
                    this.txtMomMocP.Text = this.txtMomMocP.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtMomMocP.Text = this.txtMomMocP.Text.Trim();
                    this.txtMomMocP.Text = this.txtMomMocP.Text.Replace(",,", ",");
                    if (this.txtMomMocP.Text.EndsWith(","))
                    {
                        this.txtMomMocP.Text = this.txtMomMocP.Text.Substring(0, this.txtMomMocP.Text.Length - 1);
                    }
                    if (this.txtMomMocP.Text.StartsWith(","))
                    {
                        this.txtMomMocP.Text = this.txtMomMocP.Text.Substring(1, this.txtMomMocP.Text.Length - 1);
                    }
                    if (this.txtMomMocP.Text.StartsWith(",") && this.txtMomMocP.Text.EndsWith(","))
                    {
                        this.txtMomMocP.Text = this.txtMomMocP.Text.Substring(2, this.txtMomMocP.Text.Length - 1);
                    }
                }
            }
            if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "85")
            {
                this.txtHaHong.Text = this.txtHaHong.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                this.txtHaHong.Text = this.txtHaHong.Text.Trim();
                this.txtHaHong.Text = this.txtHaHong.Text.Replace(",,", ",");
                if (this.txtHaHong.Text.EndsWith(","))
                {
                    this.txtHaHong.Text = this.txtHaHong.Text.Substring(0, this.txtHaHong.Text.Length - 1);
                }
                if (this.txtHaHong.Text.StartsWith(","))
                {
                    this.txtHaHong.Text = this.txtHaHong.Text.Substring(1, this.txtHaHong.Text.Length - 1);
                }
                if (this.txtHaHong.Text.StartsWith(",") && this.txtHaHong.Text.EndsWith(","))
                {
                    this.txtHaHong.Text = this.txtHaHong.Text.Substring(2, this.txtHaHong.Text.Length - 1);
                }
            }
            if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "3")
            {
                if (str.ToUpper() == "T")
                {
                    this.txtVomHongT.Text = this.txtVomHongT.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtVomHongT.Text = this.txtVomHongT.Text.Trim();
                    this.txtVomHongT.Text = this.txtVomHongT.Text.Replace(",,", ",");
                    if (this.txtVomHongT.Text.EndsWith(","))
                    {
                        this.txtVomHongT.Text = this.txtVomHongT.Text.Substring(0, this.txtVomHongT.Text.Length - 1);
                    }
                    if (this.txtVomHongT.Text.StartsWith(","))
                    {
                        this.txtVomHongT.Text = this.txtVomHongT.Text.Substring(1, this.txtVomHongT.Text.Length - 1);
                    }
                    if (this.txtVomHongT.Text.StartsWith(",") && this.txtVomHongT.Text.EndsWith(","))
                    {
                        this.txtVomHongT.Text = this.txtVomHongT.Text.Substring(2, this.txtVomHongT.Text.Length - 1);
                    }
                }
                if (str.ToUpper() == "P")
                {
                    this.txtVomHongP.Text = this.txtVomHongP.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                    this.txtVomHongP.Text = this.txtVomHongP.Text.Trim();
                    this.txtVomHongP.Text = this.txtVomHongP.Text.Replace(",,", ",");
                    if (this.txtVomHongP.Text.EndsWith(","))
                    {
                        this.txtVomHongP.Text = this.txtVomHongP.Text.Substring(0, this.txtVomHongP.Text.Length - 1);
                    }
                    if (this.txtVomHongP.Text.StartsWith(","))
                    {
                        this.txtVomHongP.Text = this.txtVomHongP.Text.Substring(1, this.txtVomHongP.Text.Length - 1);
                    }
                    if (this.txtVomHongP.Text.StartsWith(",") && this.txtVomHongP.Text.EndsWith(","))
                    {
                        this.txtVomHongP.Text = this.txtVomHongT.Text.Substring(2, this.txtVomHongP.Text.Length - 1);
                    }
                }
            }
            if (dtInnerScan.Rows[0][InfoInnerScan.NSCISNROOT].ToString() == "4")
            {
                this.txtThanhQuan.Text = this.txtThanhQuan.Text.Replace(dtInnerScan.Rows[0][InfoInnerScan.NSCNAME].ToString(), "");
                this.txtThanhQuan.Text = this.txtThanhQuan.Text.Trim();
                this.txtThanhQuan.Text = this.txtThanhQuan.Text.Replace(",,", ",");
                if (this.txtThanhQuan.Text.EndsWith(","))
                {
                    this.txtThanhQuan.Text = this.txtThanhQuan.Text.Substring(0, this.txtThanhQuan.Text.Length - 1);
                }
                if (this.txtThanhQuan.Text.StartsWith(","))
                {
                    this.txtThanhQuan.Text = this.txtThanhQuan.Text.Substring(1, this.txtThanhQuan.Text.Length - 1);
                }
                if (this.txtThanhQuan.Text.StartsWith(",") && this.txtThanhQuan.Text.EndsWith(","))
                {
                    this.txtThanhQuan.Text = this.txtThanhQuan.Text.Substring(2, this.txtThanhQuan.Text.Length - 1);
                }
            }
        }

        private void NoiSoiNgoaiDS()
        {
            if (this.CheckInputData())
            {
                ListDictionary param = new ListDictionary();
                param.Add(InfoScanResult.CLRISN, this._clrISN);
                param.Add(InfoScanResult.NSCISN, 0);
                param.Add(InfoScanResult.SRTSCANOUTLIST, this.tbNoiSoiNgoaiDanhSach.Text.ToString());
                param.Add(InfoScanResult.SRTOPINION, this.txtCamNghi.Text.ToString());
                param.Add(InfoScanResult.SRTSUGGESTION, this.txtDeNghi.Text.ToString());

                if (this.txtOngTaiNgoaiP.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xa7);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 2); //2: phải l; 1 : trái
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtOngTaiNgoaiP.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtOngTaiNgoaiT.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xa7);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 1);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtOngTaiNgoaiT.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtMangNhiP.Text != "168")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xa8);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 2);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtMangNhiP.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtMangNhiT.Text != "168")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xa8);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 1);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtMangNhiT.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtCuonDuoiP.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 170);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 2);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtCuonDuoiP.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtCuonDuoiT.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 170);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 1);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtCuonDuoiT.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtVachNganP.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xa9);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 2);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtVachNganP.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtVachNganT.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xa9);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 1);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtVachNganT.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtCuonGiuaP.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xab);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 2);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtCuonGiuaP.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtCuonGiuaT.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xab);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 1);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtCuonGiuaT.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtKheGiuaP.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xac);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 2);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtKheGiuaP.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtKheGiuaP.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xac);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 1);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtKheGiuaT.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtKheTrenP.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xad);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 2);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtKheTrenP.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtKheTrenT.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xad);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 1);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtKheTrenT.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtMomMocP.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xae);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 2);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtMomMocP.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtMomMocT.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0xae);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 1);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtMomMocT.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtHaHong.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 0x55);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 2);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtHaHong.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtVomHongP.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 3);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 2);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtVomHongP.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtVomHongT.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 3);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 1);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtVomHongT.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }
                if (this.txtThanhQuan.Text != "")
                {
                    param.Remove(InfoScanResult.NSCISNROOT);
                    param.Remove(InfoScanResult.SRTPOSITIONSTATUS);
                    param.Remove(InfoScanResult.SRTSCANLISTSTRING);

                    param.Add(InfoScanResult.NSCISNROOT, 4);
                    param.Add(InfoScanResult.SRTPOSITIONSTATUS, 2);
                    param.Add(InfoScanResult.SRTSCANLISTSTRING, this.txtThanhQuan.Text);
                    objController.Exec_StoreProc("sp_ScanResult", param);
                }

            }
        }

        public bool ThumbnailCallback()
        {
            return false;
        }

        private void tvNoiSoi_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                string str = this.tvNoiSoi.SelectedNode.Text.ToString();
                int count = 0;
                int num2 = 0;
                if (!this.tvNoiSoi.SelectedNode.Parent.IsSelected)
                {
                    count = this.lbNoiSoi.Items.Count;
                    if (count == 0)
                    {
                        this.lbNoiSoi.Items.Add(this.tvNoiSoi.SelectedNode.Text.ToString());
                    }
                    else
                    {
                        for (int i = 0; i < count; i++)
                        {
                            if (str == this.lbNoiSoi.Items[i].ToString())
                            {
                                num2++;
                            }
                        }
                        if (num2 == 0)
                        {
                            this.lbNoiSoi.Items.Add(this.tvNoiSoi.SelectedNode.Text.ToString());
                        }
                    }
                }
                this.NoiSoiCheck();
            }
            catch
            {
            }
        }


    }
}